package com.example.xui;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.fragment.app.FragmentTransaction;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.xui.Main.FirstFragment;
import com.example.xui.Main.FiveFragment;
import com.example.xui.Main.FourFragment;
import com.example.xui.Main.SecondFragment;
import com.example.xui.Main.ThreeFragment;
import com.example.xui.Way.changStatusIconCollor;
import com.example.xui.smlibrary.OnSpinMenuStateChangeListener;
import com.example.xui.smlibrary.SpinMenu;
import com.xuexiang.xui.XUI;

import java.util.ArrayList;
import java.util.List;

public class LoardActivity extends AppCompatActivity {
    private SpinMenu spinMenu;
    ConstraintLayout constraintLayout;
    ConstraintLayout constraintLayout1;
    ConstraintLayout constraintLayout2;
    ConstraintLayout constraintLayout3;
    ConstraintLayout constraintLayout4;
    ConstraintLayout con;
    String sno;
    boolean t=false;
    View fragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        XUI.initTheme(this);
        setContentView(R.layout.activity_loard);
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            getWindow().setNavigationBarColor(Color.TRANSPARENT);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
        changStatusIconCollor changStatusIconCollor=new changStatusIconCollor();
        changStatusIconCollor.changStatusIconCollor1(getWindow(),true);
        t=getIntent().getBooleanExtra("t",false);
        fragment=findViewById(R.id.framelayout);
        spinMenu = (SpinMenu) findViewById(R.id.spin_menu);
        con=findViewById(R.id.con);
        //String phone=getIntent().getStringExtra("phone");
        sno=getIntent().getStringExtra("sno");
        if(t==true) {
            con.setVisibility(View.INVISIBLE);
            List<String> hintStrList = new ArrayList<>();
            hintStrList.add("热门消息");
            hintStrList.add("学习资源");
            hintStrList.add("帖子");
            hintStrList.add("我的发布");
            hintStrList.add("个人主页");
           /* hintStrList.add("走走看看");
            hintStrList.add("阅读空间");
            hintStrList.add("听听唱唱");
            hintStrList.add("系统设置");*/

            spinMenu.setHintTextStrList(hintStrList);
            spinMenu.setHintTextColor(Color.parseColor("#FFFFFF"));
            spinMenu.setHintTextSize(14);

            // 设置启动手势开启菜单
            spinMenu.setEnableGesture(true);

            // 设置页面适配器
            final List<Fragment> fragmentList = new ArrayList<>();
            fragmentList.add(FirstFragment.newInstance());
            fragmentList.add(SecondFragment.newInstance());
            fragmentList.add(FiveFragment.newInstance());
            fragmentList.add(ThreeFragment.newInstance());
            fragmentList.add(FourFragment.newInstance());
            FragmentPagerAdapter fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
                @Override
                public Fragment getItem(int position) {
                    Bundle bundle=new Bundle();
                    bundle.putString("sno",sno);
                    fragmentList.get(position).setArguments(bundle);
                    return fragmentList.get(position);
                }

                @Override
                public int getCount() {
                    return fragmentList.size();
                }
            };
            spinMenu.setFragmentAdapter(fragmentPagerAdapter);

            // 设置菜单状态改变时的监听器
            spinMenu.setOnSpinMenuStateChangeListener(new OnSpinMenuStateChangeListener() {
                @Override
                public void onMenuOpened() {
                    Toast.makeText(LoardActivity.this, "SpinMenu opened", Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onMenuClosed() {
                    Toast.makeText(LoardActivity.this, "SpinMenu closed", Toast.LENGTH_SHORT).show();
                }
            });
        }else {
            spinMenu.setVisibility(View.INVISIBLE);
           // fragment.setBackgroundColor(R.color.white);
            FirstFragment firstFragment=new FirstFragment();
            SecondFragment secondFragment=new SecondFragment();
            FiveFragment fiveFragment=new FiveFragment();
            ThreeFragment threeFragment=new ThreeFragment();
            FourFragment fourFragment=new FourFragment();

            constraintLayout=findViewById(R.id.constraintLayout4);
            ImageView imageView=findViewById(R.id.imageView5);
            constraintLayout1=findViewById(R.id.constraintLayout3);
            constraintLayout2=findViewById(R.id.constraintLayout5);
            constraintLayout3=findViewById(R.id.constraintLayout6);
            constraintLayout4=findViewById(R.id.constraintLayout7);
            constraintLayout.setSelected(true);
            constraintLayout1.setSelected(false);
            constraintLayout2.setSelected(false);
            constraintLayout3.setSelected(false);
            constraintLayout4.setSelected(false);
            Bundle bundle=new Bundle();
            bundle.putString("sno",sno);
            firstFragment.setArguments(bundle);
            getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,firstFragment).commit();

            constraintLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    constraintLayout.setSelected(true);
                    constraintLayout1.setSelected(false);
                    constraintLayout2.setSelected(false);
                    constraintLayout3.setSelected(false);
                    constraintLayout4.setSelected(false);
                    Bundle bundle=new Bundle();
                    bundle.putString("sno",sno);
                    firstFragment.setArguments(bundle);
                    getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,firstFragment).commit();
                }
            });
            constraintLayout1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    constraintLayout.setSelected(false);
                    constraintLayout1.setSelected(true);
                    constraintLayout2.setSelected(false);
                    constraintLayout3.setSelected(false);
                    constraintLayout4.setSelected(false);
                    getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,secondFragment).commit();
                }
            });

            constraintLayout2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    constraintLayout.setSelected(false);
                    constraintLayout1.setSelected(false);
                    constraintLayout2.setSelected(true);
                    constraintLayout3.setSelected(false);
                    constraintLayout4.setSelected(false);
                    Bundle bundle=new Bundle();
                    bundle.putString("sno",sno);
                    fiveFragment.setArguments(bundle);
                    getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,fiveFragment).commit();
                }
            });

            constraintLayout3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    constraintLayout.setSelected(false);
                    constraintLayout1.setSelected(false);
                    constraintLayout2.setSelected(false);
                    constraintLayout3.setSelected(true);
                    constraintLayout4.setSelected(false);
                    Bundle bundle=new Bundle();
                    bundle.putString("sno",sno);
                    threeFragment.setArguments(bundle);
                    getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,threeFragment).commit();
                }
            });

            constraintLayout4.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    constraintLayout.setSelected(false);
                    constraintLayout1.setSelected(false);
                    constraintLayout2.setSelected(false);
                    constraintLayout3.setSelected(false);
                    constraintLayout4.setSelected(true);
                    Bundle bundle=new Bundle();
                    bundle.putString("sno",sno);
                    fourFragment.setArguments(bundle);
                    getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,fourFragment).commit();
                }
            });

        }

    }
}
